<template>
  <div>
    <div class="list-btn">
      时间:<DatePicker type="date" @on-change="startTime"  placeholder="选择开始时间" style="width: 200px" ></DatePicker>
      ～<DatePicker type="date" @on-change="endTime"  placeholder="选择结束时间" style="width: 200px"  ></DatePicker>
    </div>
     <div class="list-btn">
      渠道:
      <Select clearable style="width:200px" v-model="params.channelCode" placeholder="全部" >
         <Option value=" ">全部</Option>
        <Option v-for="(item,index) in channelCodeList" :value="item.channelCode" :key="index">{{ item.channelName }}</Option>
      </Select>
    </div>
    <!-- <div class="list-btn">
      订单状态:
      <Select clearable style="width:200px" v-model="params.status" placeholder="请选择" @on-change="get(params.status)">
        <Option v-for="item in typeList" :value="item.id" :key="item.id">{{ item.name }}</Option>
      </Select>
    </div> -->
    <div class="list-btn">
      <Button type="primary" @click="getList(url,'refresh');get(params.channelCode)">搜索</Button>
    </div>
    <page-list :listTitle="listTitle" :list="list" :loading="loading" @selectItem="ids = $event;"></page-list>
    <page-button :current="params.pageCurrent"  :total="total" @changePageNum="params.pageCurrent = $event; getList(url)" @changePageSize="params.pageLimit = $event; getList(url)"></page-button>
  </div>
</template>

<script>
  import listMixin from '../../mixin/list'
  import pageList from '../../template/listTemplate'
  import pageButton from '../../template/pageBtnTemplate'
  import confirmDialog from '../../template/confirmDialogTemplate'
  export default {
    mixins:[listMixin],
    components: {
      pageList,
      pageButton,
      confirmDialog
    },
    methods:{
       get(s){
        console.log(s,'sss');
        if(s){
        this.$post('/bkchannel/list',{channelCode:s})
        .then((res) => {
          if(res.code === 0){
            this.channelName = res.data.pageListData[0].channelName;
          }else{
            // this.$Message.error(res.msg);
          }
        }, (err) => {
          // this.loading = false;
          console.log(err);
        })
        }else{
          this.channelName = ""
        }

      }
    },
     mounted() {
      this.getChannel();
    },
    data () {
      return {
        tag: {
          'title': '客户结清率',
          'path': '/work/settleRate/list'
        },
         channelName:'',
        listTitle: [
          {
            title: '到期时间',
            key: 'expirationTime',
            align:'center',
             render: (h,params) =>{
              return h('div',this.getLocalDate(params.row.expirationTime))
            }
          },
          {
            title: '渠道',
            key: 'channelName',
            align:'center',
            render:(h,params) => {
            return h('div', this.channelName ? this.channelName : "全部")
          }
          },
          {
            title: '合同数',
            key: 'orderNum',
            align:'center'
          },
          {
            title: '结清数',
            key: 'settlementNum',
            align:'center'
          },
          //  {
          //   title: '正常结清数',
          //   key: 'normalSettlementNum',
          //   align:'center',
          //   // render: (h,params) =>{
          //   //   return h('div',(params.row.normalSettlementNum*100).toFixed(2))
          //   // }
          // },
          {
            title: '结清率',
            key: 'settlementRate',
            align:'center',
            render: (h,params) =>{
              return h('div',(params.row.settlementRate*100).toFixed(2)+'%')
            }
          },
          {
            title: '首逾率',
            key: 'firstOverdueRate',
            align:'center',
            render: (h,params) =>{
              let now = new Date().getTime();
              now = this.getLocalDate(now)
              let expirationTime = params.row.expirationTime;
              expirationTime = this.getLocalDate(expirationTime)
              return h('div',(new Date(expirationTime).getTime() - new Date(now).getTime())<0?(params.row.firstOverdueRate*100).toFixed(2)+'%' : '—')
            }
          },
        ],
        url: '/statistics/customer/clearanceRate',
        nameListUrl: '',
        params: {
          //status:'',
          pageCurrent: 1,
          pageLimit: 10
        },

      }
    },
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  .list-btn{
    margin-bottom: 5px;
    margin-right: 5px;
    display: inline-block;
  }
  .refresh-btn{
    float: right;
  }

</style>
